<?php require_once 'httpFilter.php'; 'conf.php'; ?>
<html>
<title>List of budgets</title>
<head>
	<link rel="stylesheet" type="text/css" media="screen" href="css/styles.css" />
	<link rel="stylesheet" type="text/css" media="screen" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.0/themes/ui-lightness/jquery-ui.css" />
	
<script type="text/javascript" src="js/utils.js"></script>
<script type="text/javascript"
	src="http://www.google.com/jsapi?key=ABQIAAAAN5ZtdO4QwxMtTu20xDDGaBRDmw7J9fBy0SHOM2DFag_Hy1S5lhQ5rqB1kcjLa1mWGmKBHM2W7xPDyQ">
</script>
<script>
	google.load("jquery", "1.4.2");
	google.load("jqueryui", "1.7.2");
</script>

<script type="text/javascript" src="viewBudgets.js">
</script>
	</head>
	<body>
		<div id="msgDlg"></div>
		<div id="confirmDlg"></div>
		<div id="loadingPic" style="display: none; position:absolute; left: 0px; top:0px; height:100%; width: 100%; text-align: center;
			           background-image:url('images/translucent.gif'); z-index: 1000;">
		<img src="images/loading2.gif" style="margin: 12%"/>
		</div>
		
		<?php include("includes/navigation.php"); ?>
		
		<table id="mytable" cellspacing="0">
		<caption>"Getting Rich Slowly" <?= $pageContext["parm1"] ?></caption>
		  <tr>
		    <th scope="row" colspan="3" class="spec">List of available budgets</th>
		  </tr>
			<tr>
			    <th scope="col" width="200">Budget Month</th>
			    <th scope="col">Created</th>
			    <th scope="col">
			    	<a href="#" id="createBudgetLink"><img src="images/new.png" title="Create new budget" alt="Create new budget" border="0" width="15"/></a>
			    	&nbsp;&nbsp;
			    	<a href="#" id="deleteBudgetLink"><img src="images/delete.png" title="Delete selected budget" alt="Delete selected budget" border="0" width="15"/></a>
			    </th>
			 </tr>
			 
			 
			 <?php
			 
			 $con = mysql_connect(GlobalConfig::db_host_name,GlobalConfig::db_username,GlobalConfig::db_password);
			if (!$con)
			  {
			  die('Could not connect: ' . mysql_error());
			  }
			
			mysql_select_db(GlobalConfig::db_name, $con);
			
			$result = mysql_query("SELECT * FROM budget where id > 1 and userid=". $_SESSION["userid"]. " order by created desc");
			
			while($row = mysql_fetch_array($result))
			  {
			  	?>
			  	 	<tr>
			  	 		<th scope='row' class='spec''><a href='index.php?mod=editBudget&budgetId=<?php echo $row['id'] ?>' class="budgetMonth"><?php echo $row['month'] ?></a></th>
			  	 		<td class='spec'><?php echo $row['created'] ?></td>
			  	 		<td><input type="radio" name="selectBudget" value="<?= $row['id'] ?>"></td>
			  	 	</tr>
				<?php
			  }
			
			mysql_close($con);
	  
			 ?>
			
			<tr style="display: none;" id="emptyRow"><th colspan="3" class="nobg">&nbsp;</th></tr>
			<tr style="display: none;" id="newRowTitle">
			    <th scope="col">Pick Month & Year</th>
			    <th scope="col" colspan="2">Template</th>
			 </tr>
			 <tr style="display: none;" id="newRow">
			    <th scope='row' class='spec'>
					<select id="budgetMonth">
					  <option value="January">January</option>
					  <option value="February">February</option>
					  <option value="March">March</option>
					  <option value="April">April</option>
					  <option value="May">May</option>
					  <option value="June">June</option>
					  <option value="July">July</option>
					  <option value="August">August</option>
					  <option value="September">September</option>
					  <option value="October">October</option>
					  <option value="November">November</option>
					  <option value="December">December</option>
					</select>
					
					<select id="budgetYear">
					  <option value="2010">2010</option>
					  <option value="2011" selected="selected">2011</option>
					  <option value="2012">2012</option>
					  <option value="2013">2013</option>
					  <option value="2014">2014</option>
					</select>
				</th>
			    <td class='spec' colspan="2" algin="left">
					<input type="radio" name="budgetTemplate" value="inbuiltTemplate" />Use in-built template
					<input type="radio" name="budgetTemplate" value="existingBudget" />Use selected budget
				</td>
			 </tr>
			 <tr style="display: none;" id="submitNewBudgetRow">
			 	<th colspan="3" class="nobg">
			 		<button id="createBudgetButton">Create Budget</button>
			 		<button id="cancelBudgetButton">Cancel</button>
			 	</th>
			 </tr>
		</table>
		
	<?php include("includes/footer.php"); ?>
	</body>
</html>